/* small demo app that just includes a cipher/hash/prng */
#include <tomcrypt.h>

int main(void)
{
   unsigned char key[32], IV[32], buffer[512];
   symmetric_CTR ctr;
   int err;
   
   /* register AES */
   if (register_cipher(&aes_desc) == -1) 
   {
   	 printf("Error registering cipher.\n");
   	 return -1;
   };
   
   /* somehow fill out key and IV */
   memcpy(key,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef",32);
   memcpy(IV,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef",32);
   
   /* start up CTR mode */
   if ((err = ctr_start(
   		find_cipher("aes"), /* index of desired cipher */
   					    IV, /* the initial vector */
   					   key, /* the secret key */
   					    32, /* length of secret key */
   					     0, /* default # of rounds */
 CTR_COUNTER_LITTLE_ENDIAN,
 					  &ctr)
 		) != CRYPT_OK) 
 	{
 		printf("ctr_start error: %s\n", error_to_string(err));
 		return -1;
 	}			  
 	
 	/* somehow fill buffer then encrypt it */
 	if ((err = ctr_encrypt(		buffer, /* plaintext */
 								buffer, /* ciphertext */
 						sizeof(buffer), /* length of plaintext pt */
 								 &ctr)  /* CTR state */
 	) != CRYPT_OK) 
 	{
 		printf("ctr_encrypt error: %s\n", error_to_string(err));
 		return -1;	
 	}
 	
 	if ((err = ctr_decrypt(			buffer, /* ciphertext */
 									buffer, /* plaintext */
 							sizeof(buffer),
 									 &ctr)
 	) != CRYPT_OK) 
 	{
 		printf("ctr_decrypt error: %s\n", error_to_string(err));
 		return -1;
 	}
 	 	
 	/* terminate the stream */
 	if ((err = ctr_done(&ctr)) != CRYPT_OK) 
 	{
 		printf("ctr_done error: %s\n", error_to_string(err));
 		return -1;	
 	}
 	
 	zeromem(key, sizeof(key));
 	zeromem(&ctr, sizeof(ctr));
   //register_prng(&yarrow_desc);
   //register_hash(&sha256_desc);
   return 0;
}

/* $Source: /cvs/libtom/libtomcrypt/demos/small.c,v $ */
/* $Revision: 1.3 $ */
/* $Date: 2006/06/07 22:25:09 $ */
